package com.ruoyi.project.modules.tableRelation.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.modules.tableRelation.domain.TableRelation;
import com.ruoyi.project.modules.tableRelation.service.ITableRelationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 外健关系Controller
 * 
 * @author smallrain
 * @date 2022-01-23
 */
@Controller
@RequestMapping("/tableRelation/tableRelation")
public class TableRelationController extends BaseController
{
    private String prefix = "tableRelation/tableRelation";

    @Autowired
    private ITableRelationService tableRelationService;

    @RequiresPermissions("tableRelation:tableRelation:view")
    @GetMapping()
    public String tableRelation()
    {
        return prefix + "/tableRelation";
    }

    /**
     * 查询外健关系列表
     */
    @RequiresPermissions("tableRelation:tableRelation:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TableRelation tableRelation)
    {
        startPage();
        List<TableRelation> list = tableRelationService.selectTableRelationList(tableRelation);
        return getDataTable(list);
    }

    /**
     * 导出外健关系列表
     */
    @RequiresPermissions("tableRelation:tableRelation:export")
    @Log(title = "外健关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TableRelation tableRelation)
    {
        List<TableRelation> list = tableRelationService.selectTableRelationList(tableRelation);
        ExcelUtil<TableRelation> util = new ExcelUtil<TableRelation>(TableRelation.class);
        return util.exportExcel(list, "外健关系数据");
    }

    /**
     * 新增外健关系
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存外健关系
     */
    @RequiresPermissions("tableRelation:tableRelation:add")
    @Log(title = "外健关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TableRelation tableRelation)
    {
        return toAjax(tableRelationService.insertTableRelation(tableRelation));
    }

    /**
     * 修改外健关系
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TableRelation tableRelation = tableRelationService.selectTableRelationById(id);
        mmap.put("tableRelation", tableRelation);
        return prefix + "/edit";
    }

    /**
     * 修改保存外健关系
     */
    @RequiresPermissions("tableRelation:tableRelation:edit")
    @Log(title = "外健关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TableRelation tableRelation)
    {
        return toAjax(tableRelationService.updateTableRelation(tableRelation));
    }

    /**
     * 删除外健关系
     */
    @RequiresPermissions("tableRelation:tableRelation:remove")
    @Log(title = "外健关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tableRelationService.deleteTableRelationByIds(ids));
    }
}
